cc.Class({
  extends: cc.Component,
  properties: {
    spine: sp.Skeleton,
    focusNode: cc.Node,
    fingerSpine: sp.Skeleton,
    guideNode: cc.Node,
    guideLabel: cc.Label
  },
  onLoad: function () {
    var e = this;
    cc.guideManager = this;
    this.guideNode && (this.guideNode.active = false);
    this.hackButton();
    cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function (t) {
      e.node.parent = t;
    });
  },
  isGuiding: function () {
    return this.guideNode.active;
  },
  showGuide: function (e, t, o) {
    var a = this;
    var n = -1;
    !function e() {
      if (++n >= t.length) {
        a.hideGuideDialog();
        a.guideConfig = null;
        o && o(true);
      } else {
        var i = t[n];
        a.showGuideDialog(i, e);
        o && o(false, n);
      }
    }();
  },
  showGuideDialog: function (e, t) {
    var o = this;
    this.guideConfig = {
      btn: e.btn,
      r: e.r,
      cb: t
    };
    this.guideNode.zIndex = cc.macro.MAX_ZINDEX;
    this.guideNode.active = true;
    this.spine.node.y = e.y ? e.y : e.t ? 200 : 0;
    this.spine.setAnimation(0, e.r ? "jiaoxue1_R" : "jiaoxue1", false);
    this.spine.setCompleteListener(function () {
      o.spine.setAnimation(0, e.r ? "jiaoxue2_R" : "jiaoxue2", true);
      o.spine.setCompleteListener(null);
    });
    this.guideLabel.string = e.tip;
    this.guideLabel.node.stopAllActions();
    this.guideLabel.node.opacity = 0;
    this.guideLabel.node.runAction(cc.fadeIn(.5));
    var a = e.focus ? e.focus.getBoundingBoxToWorld() : cc.rect();
    var n = this.guideNode.parent.convertToNodeSpaceAR(a.center);
    this.focusNode.active = true;
    this.focusNode.x = n.x;
    this.focusNode.y = n.y;
    this.focusNode.width = this.focusNode.height = 0;
    this.focusNode.opacity = 255;
    cc.tween(this.focusNode).to(.5, {
      width: a.width,
      height: a.height
    }).start();
    this.fingerSpine.node.active = !e.hideFinger;
    this.fingerSpine.node.active && this.fingerSpine.setAnimation(0, e.fingerAni || "dianji", true);
  },
  hideGuideDialog: function () {
    var e = this;
    this.spine.setAnimation(0, this.guideConfig.r ? "jiaoxue3_R" : "jiaoxue3", false);
    this.spine.setCompleteListener(function () {
      e.guideNode.active = false;
      e.spine.setCompleteListener(null);
    });
    this.guideLabel.node.runAction(cc.fadeOut(.2));
    this.focusNode.width = 0;
    this.focusNode.height = 0;
    this.focusNode.active = false;
    this.fingerSpine.node.active = false;
  },
  guideLogAndCheckBtnClick: function (e) {
    this.guideConfig && this.guideConfig.btn == e && this.onStepFinished();
  },
  onStepFinished: function () {
    this.guideConfig && this.guideConfig.cb && this.guideConfig.cb();
  },
  onClickGuide: function () {
    console.log("onClickGuide");
    this.guideConfig && (this.guideConfig.btn || this.onStepFinished());
  },
  hackButton: function () {
    if (!cc.hasHackButton) {
      cc.hasHackButton = true;
      var e = cc.Button.prototype._onTouchEnded;
      cc.Button.prototype._onTouchEnded = function (t) {
        this.interactable && this.enabledInHierarchy && this._pressed && cc.guideManager.guideLogAndCheckBtnClick(this.node.name);
        e.call(this, t);
      };
    }
  }
});